import java.util.Scanner;
public class Test {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int n = in.nextInt();

        int N = 100000;
        int[] fib = new int[N];
        fib[0] = 0;
        fib[1] = 1;
        for(int i = 2;i < N; i++) {
            fib[i] = fib[i-1] + fib[i-2];

        }

        int i = 0;
        for(;i < N-1; i++) {
            if(fib[i] <= n && fib[i + 1] >= n) {
                break;
            }

        }
        int min = Math.min(n - fib[i],fib[i + 1] -n);
        System.out.println(min);

    }
}
